package com.qf.dao.impl;

import com.qf.dao.GoodTypeDao;
import com.qf.entity.GoodType;
import com.qf.util.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author AzureSky_X
 * @Date 2020/11/17 21:05
 * @Version 1.0
 */
public class GoodTypeDaoImpl implements GoodTypeDao {
    QueryRunner qr=new QueryRunner();
    @Override
    public List<GoodType> selectGoodType() {
        String sql="select * from tb_good_type where parentId=0";
        List<GoodType> query=null;
        try {
            query=qr.query(DbUtils.getConnection(),sql, new BeanListHandler<>(GoodType.class));
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return query;
    }

    @Override
    public GoodType selectGoodTypeById(Integer typeId) {
        String sql="select * from tb_good_type where id=?";
        GoodType query=null;
        try {
            query=qr.query(DbUtils.getConnection(),sql,new BeanHandler<>(GoodType.class),typeId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return query;
    }
}
